/**
 * Title:        代理数据同步
 * Company:      泛微软件
 */


package checkDetail;

import general.BaseBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;



public class CreatedocFieldCheck extends BaseBean implements CheckBase  {

    @Override
    public JSONObject checkData(HashMap dataMap) {
        setRecordSet();
        (new BaseBean()).writeLog("RequestSequenceCheck  start");

        List resultList = new ArrayList();
        String result = resultOk;

        //currentoperator
        int curoptCurVal = -1;
        int curoptMaxId = -1;
        String sqlStr = "";
        sqlStr += " select wfb.workflowname,workflow_createdoc.flowcodefield,workflow_createdoc.flowdocfield,workflow_billfield.fieldhtmltype,workflow_billfield.type";
        sqlStr += " ,wfb.formid,workflow_createdoc.workflowid,wfb.isbill";
        sqlStr += " from workflow_createdoc";
        sqlStr += " inner join workflow_base wfb on wfb.id = workflow_createdoc.workflowid";
        sqlStr += " inner join workflow_billfield on workflow_billfield.id = workflow_createdoc.flowdocfield";
        sqlStr += "  where status='1' and (flowcodefield != -1 or flowdocfield != -1)";
        recordSet.executeSql(sqlStr);
        while(recordSet.next()){
            String workflowname = recordSet.getString("workflowname");
            String flowcodefield = recordSet.getString("flowcodefield");
            String flowdocfield = recordSet.getString("flowdocfield");
            String fieldhtmltype = recordSet.getString("fieldhtmltype");
            String formid = recordSet.getString("formid");
            String workflowid = recordSet.getString("workflowid");
            String isbill = recordSet.getString("isbill");
            String type = recordSet.getString("type");
            if(flowcodefield.equals(flowdocfield)){
                result = resultNeedFix;
                Map resultMap = new HashMap<String,String>();
                resultMap.put("showMessage","流程[" + workflowname + "]流程编号和流程创建文档使用同一个字段，会导致编号无法生成");
                resultMap.put("linkurl","/workflow/workflow/CreateDocumentByWorkFlowForWf.jsp?isdialog=0&ajax=1&wfid=" + workflowid + "&formid=" + formid + "&isbill=" + isbill);
                resultMap.put("seqid","workflow_requestlog_id");
                resultList.add(resultMap);
            }
            if(!fieldhtmltype.equals("3") || !type.equals("9")){
                result = resultNeedFix;
                Map resultMap = new HashMap<String,String>();
                resultMap.put("showMessage","流程[" + workflowname + "]流程创建文档的字段类型不是文档类型");
                resultMap.put("linkurl","/workflow/workflow/CreateDocumentByWorkFlowForWf.jsp?isdialog=0&ajax=1&wfid=" + workflowid + "&formid=" + formid + "&isbill=" + isbill);
                resultMap.put("seqid","workflow_requestlog_id");
                resultList.add(resultMap);
            }
        }
        if(resultList.size() <= 0){
            result = resultOk;
            resultList.add("数据检测正常。");
        }
    
        
        (new BaseBean()).writeLog("RequestSequenceCheck  end");
        return formatReturnJsonCheck(result, resultList,this);
    }

    @Override
    public JSONObject fixData(HashMap dataMap) {

        needReload = "1";
        return checkData(new HashMap());
        
        
    }

    @Override
    public String getClassName() {
        return "流程存为文档检测";
    }

    @Override
    public String getClassDesc() {
        return "检测流程存为文档目标字段是否和流程编号是同一个字段，如果是，则无法生成编号，如果是浏览按钮或者是附件上传字段，会导致该字段无法解析";
    }

}



